package com.zhoukx.nio;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.channels.FileChannel;

/**
 * 实例要求:
 * 使用 FileChannel(通道) 和 方法  transferFrom ，完成文件的拷贝
 */
public class NIOFilerChannerl04 {
    public static void main(String[] args) throws IOException {
        // 创建相关流
        FileInputStream fileInputStream = new FileInputStream("d:\\1.jpg");
        FileOutputStream fileOutputStream = new FileOutputStream("d:\\2.jpg");

        // 获取各个流对应的filechannel
        FileChannel source = fileInputStream.getChannel();
        FileChannel target = fileOutputStream.getChannel();
        // 使用transferForm完成拷贝
        target.transferFrom(source,0,source.size());

        source.close();
        target.close();
        fileInputStream.close();
        fileOutputStream.close();


    }
}
